package com.homegoods.classify.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.homegoods.classify.R;
import com.homegoods.classify.model.RightModel;

import java.util.List;

/**
 * add shibo.zheng
 * 19/06/22
 * 品牌fragment 中logo展示的adapter
 * （临时使用方案，可通过viewtype区分，设置不同的layout）
 */

public class ZPBrandItemAdapter extends RecyclerView.Adapter<ZPBrandItemAdapter.ZPBrandItemViewHodler> {
    private Context mContext;
    private List<RightModel> rightModels;

    public ZPBrandItemAdapter(Context mContext, List<RightModel> rightModels) {
        this.mContext = mContext;
        this.rightModels = rightModels;
    }

    @NonNull
    @Override
    public ZPBrandItemViewHodler onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.classify_brand_child_item, viewGroup, false);
        ZPBrandItemViewHodler viewHodler = new ZPBrandItemViewHodler(view);
        return viewHodler;
    }

    @Override
    public void onBindViewHolder(@NonNull ZPBrandItemViewHodler zpBrandItemViewHodler, int i) {
        zpBrandItemViewHodler.brandItemImg.setImageResource(rightModels.get(i).getRightImg());
    }

    @Override
    public int getItemCount() {
        return rightModels.size();
    }

    public class ZPBrandItemViewHodler extends RecyclerView.ViewHolder {
        private ImageView brandItemImg;

        public ZPBrandItemViewHodler(@NonNull View itemView) {
            super(itemView);
            brandItemImg = itemView.findViewById(R.id.brand_child_img);
        }
    }

}
